<?php
namespace app\admin\controller;
use think\Controller;
class Bis extends  Controller
{
    private  $obj;
    public function _initialize() {
        $this->obj = model("Bis");
    }
    //status 为1 的商户列表
    public function index(){
        $info = $this->obj->getBisByStatus(1);
        return $this->fetch('',['bis'=>$info]);
    }


    public function apply(){
        $result =  model('Bis')->getBisByStatus();
        $this->assign('bis',$result);
        return $this->fetch();
    }

    public function detail($id){
        $citys = model('City')->getNormalCitysByParentId();
        $categorys = model('Category')->getNormalCategoryByParentId();
        $bisData = model("Bis")->getDetailByIdWithout($id);
        $locationData = model('BisLocation')->getNormalLocationByBisIdWith($id);
        $accountData = model('BisAccount')->getNormalAccountByBisIdWith($id);
        return $this->fetch('',[
            'bisData'=> $bisData,
            'citys' => $citys,
            'locationData' => $locationData,
            'accountData' => $accountData,
            'categorys' =>  $categorys]);
    }
    public function status(){
        $data = input('get.');
        $res = model("Bis")->where(['id' => $data['id']])->update(['status'=>$data['status']]);
        $location = model('BisLocation')->where(['bis_id' => $data['id']])->update([
            'status'=>$data['status'],
            'is_main' => 1,
        ]);
        $account = model('BisAccount')->where(['bis_id' => $data['id']])->update([
            'status'=>$data['status'],
            'is_main' => 1,
        ]);
        $result =  model('Bis')->getDetailByIdWithout($data['id']);
        if($res && $location && $account){
            //status 1 成功， status 2 不通过 status -1 删除
           /* \phpmailer\Email::send($result['email'],$result['status'],'status 1 成功， status 2 不通过 status -1 删除');*/
            $this->success('状态更新成功');
        }else{
            $this->error('状态更新失败');
        }

    }

}
